# SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only)
# SPDX-FileCopyrightText: 2015-2024 EfficiOS Inc.

ccflags-y += -DLTTNG_LINUX_MAJOR=$(VERSION)
ccflags-y += -DLTTNG_LINUX_MINOR=$(PATCHLEVEL)
ccflags-y += -DLTTNG_LINUX_PATCH=$(SUBLEVEL)

# Work-around for distro-specific public modules ABI breakages.
# Some distributions break the public module instrumentation ABI
# compared to upstream stable kernels without providing other mean than
# the kernel EXTRAVERSION to figure it out. Translate this information
# into a define visible from the C preprocessor.

DEB_API_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/abi-debian-version.sh $(CURDIR))

ifneq ($(DEB_API_VERSION), 0)
  ccflags-y += -DDEBIAN_API_VERSION=$(DEB_API_VERSION)
endif

RHEL_API_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/abi-rhel-version.sh $(CURDIR))

ifneq ($(RHEL_API_VERSION), 0)
  ccflags-y += -DRHEL_API_VERSION=$(RHEL_API_VERSION)
endif

SLE_API_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/abi-sle-version.sh $(CURDIR))

ifneq ($(SLE_API_VERSION), 0)
  ccflags-y += -DSLE_API_VERSION_MAJOR=$(word 1, $(SLE_API_VERSION))
  ccflags-y += -DSLE_API_VERSION_MINOR=$(word 2, $(SLE_API_VERSION))
  ccflags-y += -DSLE_API_VERSION_PATCH=$(word 3, $(SLE_API_VERSION))
endif

FEDORA_REVISION_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/abi-fedora-version.sh $(CURDIR))

ifneq ($(FEDORA_REVISION_VERSION), 0)
  ccflags-y += -DFEDORA_REVISION_VERSION=$(FEDORA_REVISION_VERSION)
endif

RT_PATCH_VERSION:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/rt-patch-version.sh $(CURDIR))

ifneq ($(RT_PATCH_VERSION), 0)
  ccflags-y += -DRT_PATCH_VERSION=$(RT_PATCH_VERSION)
endif

EXTRA_VERSION_NAME:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/extra-version-name.sh $(TOP_LTTNG_MODULES_DIR))

ifneq ($(EXTRA_VERSION_NAME), 0)
  ccflags-y += -DLTTNG_EXTRA_VERSION_NAME='"$(EXTRA_VERSION_NAME)"'
endif

EXTRA_VERSION_GIT:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/extra-version-git.sh $(TOP_LTTNG_MODULES_DIR))

ifneq ($(EXTRA_VERSION_GIT), 0)
  ccflags-y += -DLTTNG_EXTRA_VERSION_GIT='"$(EXTRA_VERSION_GIT)"'
endif

EXTRA_VERSION_PATCHES:=$(shell $(TOP_LTTNG_MODULES_DIR)/scripts/extra-version-patches.sh $(TOP_LTTNG_MODULES_DIR))

mnt_ns_dep = $(srctree)/fs/mount.h
ifeq ($(wildcard $(mnt_ns_dep)),)
    ccflags-y += -DLTTNG_MNT_NS_MISSING_HEADER
endif

# vim:syntax=make
